<?php
require_once ('../../include/phpmailer/class.phpmailer.php');
require_once ('../../config.inc.php');

class Email {
	/**
	 * 发送提示邮件给管理员
	 * @param unknown_type $subject
	 * @param unknown_type $body
	 */
	public static function tipEmailToAdmin($subject, $body) {
		return Email::smtp_mail(ADMIN_EMAIL, $subject, $body);
	}
	/**
	 * 给用户发送邮件
	 * @param unknown_type $sendto_email
	 * @param unknown_type $subject
	 * @param unknown_type $body
	 */
	public static function tipToUser($sendto_email, $subject, $body) {
		return Email::smtp_mail($sendto_email, $subject, $body);
	}
	
	/**
	 * 发送邮件
	 * 
	 * @param unknown_type $sendto_email        	
	 * @param unknown_type $subject        	
	 * @param unknown_type $body        	
	 * @param unknown_type $att        	
	 */
	protected static function smtp_mail($sendto_email, $subject, $body) {
		$mail = new PHPMailer ();
		$mail->IsSMTP ();
		
		$mail->Host = EMAIL_HOST;
		$mail->Username = EMAIL_USER;
		$mail->Password = EMAIL_PASS;
		
		$mail->FromName = EMAIL_NAME;
		$mail->SMTPAuth = true;
		$mail->From = $mail->Username;
		$mail->CharSet = "utf8";
		$mail->Encoding = "base64";
		$mail->AddAddress ( $sendto_email );
// 		foreach ( $att as $key => $val ) {
// 			if (! empty ( $val )) {
// 				$mail->AddAttachment ( $val ); // 注意要给绝对路径
// 			}
// 		}
		
		$mail->IsHTML ( true );
		$mail->Subject = $subject;
		$mail->Body = $body;
		$mail->AltBody = "text/html";
		if (! $mail->Send ()) {
			return "邮件错误信息: " . $mail->ErrorInfo;
		} else {
			return "邮件发送成功!";
		}
	}

}
?>